package com.codingclub.domain.handle.subject;

import com.codingclub.common.enums.SubjectInfoTypeEnum;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 工厂模式获取题目类型处理器
 */
@Component
public class SubjectTypeHandlerFactory{
    private static final Map<SubjectInfoTypeEnum,SubjectTypeHandler>handlerMap=new HashMap<>();

    public SubjectTypeHandlerFactory( List<SubjectTypeHandler>handlers){
        //初始化map
        if(handlers!=null&&!handlers.isEmpty()){
            for (SubjectTypeHandler handler : handlers) {
                handlerMap.put(handler.getHandlerType(),handler);
            }
        }
    }
    public static SubjectTypeHandler getHandle(SubjectInfoTypeEnum subjectInfoTypeEnum){
        return handlerMap.get(subjectInfoTypeEnum);
    }
}
